#!/usr/bin/env python3
# -*- coding:utf-8 -*-
import os
import configparser
from config.conf import cm

HOST = 'HOST'
USERINFO = 'USERINFO'
RETRTCOUNT = 'RETRTCOUNT'

class ReadConfig:
    """配置文件"""

    def __init__(self):
        self.config = configparser.RawConfigParser()  # 当有%的符号时请使用Raw读取
        self.config.read(cm.ini_file, encoding='utf-8')

    def _get(self, section, option):
        """获取"""
        return self.config.get(section, option)

    def _set(self, section, option, value):
        """更新"""
        self.config.set(section, option, value)
        with open(cm.ini_file, 'w') as f:
            self.config.write(f)

    @property
    def url(self):
        return self._get(HOST,'host')

    @property
    def enterprise_url(self):
        return self._get(HOST, 'enterprise_host')

    @property
    def bop_url(self):
        return self._get(HOST, 'bop_jzsz')

    @property
    def mp_url(self):
        return self._get(HOST, 'mp_host')

    @property
    def bop_account(self):
        return self._get(USERINFO,'bop_account')

    @property
    def bop_password(self):
        return self._get(USERINFO,'bop_password')

    @property
    def account(self):
        return self._get(USERINFO, 'account')

    @property
    def pwd(self):
        return self._get(USERINFO, 'password')

    @property
    def enterprise_account(self):
        return self._get(USERINFO, 'enterprise_account')

    @property
    def enterprise_password(self):
        return self._get(USERINFO, 'enterprise_password')

    @property
    def login_retry_count(self):
        return int(self._get(RETRTCOUNT, 'login'))


ini = ReadConfig()

if __name__ == '__main__':
    print(ini.url)
    print(ini.account)